#ifndef TSW_TIMER_H
#define TSW_TIMER_H

#include "mytype.h"

#ifdef __cplusplus
extern "C"
{
#endif

	struct swtm_cb_str
	{
		uint32_t period;
		uint32_t tick_cnt;
		uint8_t mode;
		uint8_t run_st;
		uint8_t pulse;
		uint8_t wave;
		void (*task)(void);
		struct swtm_cb_str *next;
	};

	typedef struct swtm_cb_str swtm_cb_type;

	struct swtm_manage_str
	{
		uint16_t tick_old;
		swtm_cb_type *list;
	};

	typedef struct swtm_manage_str swtm_manage_type;

	void swtm_init(swtm_manage_type *vect, uint16_t tick);
	void swtm_add(swtm_manage_type *vect, swtm_cb_type *tm_cb, void (*task)(void)); 
	void swtm_del(swtm_manage_type *vect, swtm_cb_type *tm_cb);
	void swtm_reset(swtm_cb_type *tm_cb);							
	void swtm_start(swtm_cb_type *tm_cb);							
	void swtm_stop(swtm_cb_type *tm_cb);							
	void swtm_set(swtm_cb_type *tm_cb, uint8_t mode, uint32_t cmp); 
	void swtm_run(swtm_manage_type *vect, uint16_t tick);			

	typedef struct
	{
		int32_t sec_set;	 
		int32_t sec_cnt;	 
		int8_t rtc_sec_old;	 
		int8_t reset_at_end; 
		int8_t b_time_end;	 
	} time_run_handle_type;

	void time_run_handle(time_run_handle_type *obj, int8_t rtc_sec_now);
	void time_run_reset(time_run_handle_type *obj, int8_t rtc_sec_now);

	typedef struct
	{
		uu8 en;
		uu8 st;
		uu16 cnt;
		uu16 otsv;
		void (*callback)(void);
	} swdg_type;

	void swdg_open(swdg_type *obj, uu16 ot, void (*back)(void));
	void swdg_close(swdg_type *obj);
	void swdg_feed(swdg_type *obj);
	void swdg_run(swdg_type *obj);

#ifdef __cplusplus
}
#endif

#endif 
